// 角色相关的接口函数
import request from '@/utils/request'
import type {RoleModel, RoleListModel, RolePageListModel} from './model/roleModel'

// 枚举类型的接口地址
enum Api {
  // 根据id列表批量删除角色
  BatchRemoveRoles = '/admin/acl/role/batchRemove',
  // 获取角色
  GetRole = 'GET /admin/acl/role/get',
  // 根据id删除角色
  RemoveRoleById = '/admin/acl/role/remove',
  // 新增角色
  SaveRole = '/admin/acl/role/save',
  // 修改角色
  UpdateRole = '/admin/acl/role/update',
  // 获取角色分页列表
  GetRolesPageList = '/admin/acl/role'
}

// 批量删除角色
export const batchRemoveRolesApi = (ids: string[]) => request.delete<any, null>(Api.BatchRemoveRoles, {data: ids})
// 删除角色
export const removeRoleByIdApi = (id: string) => request.delete<any, null>(Api.RemoveRoleById + `/${id}`)
// 新增角色
export const saveRoleApi = (role: RoleModel) => request.post<any, null>(Api.SaveRole, role)
// 修改角色
export const updateRoleApi = (role: RoleModel) => request.put<any, null>(Api.UpdateRole, role)
// 获取角色
export const getRoleApi = (id: string) => request.get<any, RoleModel>(Api.GetRole + `/${id}`)
// 获取角色分页列表
export const getRolesPageListApi = (page: number, limit: number, searchParams: object) => request.get<any, RolePageListModel>(Api.GetRolesPageList + `/${page}/${limit}`, {
  params: searchParams
})


// 新增/修改角色
export const saveOrUpdateApi = (role: RoleModel) => {
  if (role.id) {
    return request.put<any, null>(Api.UpdateRole, role)
  } else {
    return request.post<any, null>(Api.SaveRole, role)
  }
}